package com.java.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;

import com.java.mapper.LoginMapper;
import com.java.pojo.OneMenu;
import com.java.service.LoginService;
import com.java.utils.MD5Tool;


@Service
public class LoginServiceImpl implements LoginService {

	@Resource
    private LoginMapper loginmapper;
	
	public boolean login(String username, String password, HttpSession session) {
		// TODO Auto-generated method stub
		try {
			password = MD5Tool.md5(password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		int login = loginmapper.login(username, password);
		if(login == 1){
			List<OneMenu> oneMenuList = loginmapper.getAuthorityByUsername(username);
			session.setAttribute("oneMenuList",oneMenuList);
			session.setAttribute("username", username);
			return true;
		}
		return false;
	}

}
